package com.ssm.zy.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.zy.common.controller.BaseController;
import com.ssm.zy.common.result.Result;
import com.ssm.zy.common.result.ResultCode;
import com.ssm.zy.pojo.Post;
import com.ssm.zy.pojo.User;
import com.ssm.zy.pojo.vo.PostVo;
import com.ssm.zy.service.AdministratorsService;
import com.ssm.zy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

/**
 * @author 柳艾迪~
 * @version 1.0
 */
@RestController
@RequestMapping("/administrators")//管理员
public class AdministratorsController extends BaseController {
    @Autowired
    private AdministratorsService administratorsService;

    @PutMapping ("/examine")//审核
    public Result examine(Integer postId,int judge){
        int i=administratorsService.examine(postId,judge);
        if(i==0){
            return Result.err();
        }else {
            return Result.ok();
        }

    }

    @DeleteMapping("/deletePost/{postId}")//删除帖子
    public Result deletePost(@PathVariable(name = "postId") String postId){
        int i=administratorsService.deletePost(Integer.parseInt(postId));
        if(i==0){
            return Result.err();
    }
        return Result.ok();
    }

    @GetMapping("/checkExamine") //查看需要审核的帖子
    public Result<PostVo> checkExamine(
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "5")Integer pageSize
    ){
        PageInfo<PostVo> i=administratorsService.checkExamine(userId,pageNum,pageSize);
        if(i.getSize()==0){
            return Result.err();
        }
        return new Result(ResultCode.SUCCESS,i);
    }

    @GetMapping("/findAllPost") //查找所有帖子
    public Result<PostVo> findAllPost(){
        List<PostVo> i=administratorsService.findAllPost(userId);
        if(i.size()==0){
            return Result.err();
        }
        return new Result(ResultCode.SUCCESS,i);
    }

    @GetMapping("/findAllUser") //查找所有用户
    public Result<User> findAllUser(
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "5")Integer pageSize
    ){
       PageInfo<User> i=administratorsService.findAllUser(pageNum,pageSize);
        if(i.getSize()==0){
            return Result.err();
        }
        return new Result(ResultCode.SUCCESS,i);
    }

}
